package zj.com.db;

import android.app.NotificationManager;
import android.content.Context;
import android.support.v7.app.NotificationCompat;

import org.xutils.DbManager;
import org.xutils.x;

import java.io.File;

/**
 * Created by xi on 16/6/22.
 */
public class DBUtil {



    private DBUtil(){};
    private static DBUtil instance = new DBUtil();
    public Context context;
    DbManager.DaoConfig daoConfig = new DbManager.DaoConfig()
            .setDbName("zj.db")
                    // 不设置dbDir时, 默认存储在app的私有目录.
            .setDbDir(new File("/sdcard/zj/")) // "sdcard"的写法并非最佳实践, 这里为了简单, 先这样写了.
            .setDbVersion(2)
            .setDbOpenListener(new DbManager.DbOpenListener() {
                @Override
                public void onDbOpened(DbManager db) {
                    // 开启WAL, 对写入加速提升巨大
                    db.getDatabase().enableWriteAheadLogging();
                }
            })
            .setDbUpgradeListener(new DbManager.DbUpgradeListener() {
                @Override
                public void onUpgrade(DbManager db, int oldVersion, int newVersion) {
                    // TODO: ...
                    // db.addColumn(...);
                    // db.dropTable(...);
                    // ...
                    // or
                    // db.dropDb();
                }
            });


    public static DBUtil getInstance(Context context){
        context = context;
        return instance;
    }

    public DbManager getDBManager(){

        DbManager db = x.getDb(daoConfig);
        return db;
    }
}
